package com.ruoyi.web.controller.system;

import java.util.List;
import java.util.Arrays;

import lombok.RequiredArgsConstructor;
import javax.validation.constraints.*;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.validation.annotation.Validated;
import com.ruoyi.common.annotation.RepeatSubmit;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.vo.ZsyyCameraApplyVo;
import com.ruoyi.system.bo.ZsyyCameraApplyQueryBo;
import com.ruoyi.system.bo.ZsyyCameraApplyAddBo;
import com.ruoyi.system.bo.ZsyyCameraApplyEditBo;
import com.ruoyi.system.service.IZsyyCameraApplyService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import springfox.documentation.annotations.ApiIgnore;

/**
 * 摄像头开通Controller
 *
 * @author wangghua
 * @date 2021-07-14
 */
@ApiIgnore
@Api(value = "摄像头开通控制器", tags = {"摄像头开通管理"})
@RequiredArgsConstructor(onConstructor_ = @Autowired)
@RestController
@RequestMapping("/system/cameraApply")
public class ZsyyCameraApplyController extends BaseController {

    private final IZsyyCameraApplyService iZsyyCameraApplyService;

    /**
     * 查询摄像头开通列表
     */
    @ApiOperation("查询摄像头开通列表")
    @PreAuthorize("@ss.hasPermi('system:cameraApply:list')")
    @GetMapping("/list")
    public TableDataInfo<ZsyyCameraApplyVo> list(@Validated ZsyyCameraApplyQueryBo bo) {
        return iZsyyCameraApplyService.queryPageList(bo);
    }

    /**
     * 导出摄像头开通列表
     */
    @ApiOperation("导出摄像头开通列表")
    @PreAuthorize("@ss.hasPermi('system:cameraApply:export')")
    @Log(title = "摄像头开通", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult<ZsyyCameraApplyVo> export(@Validated ZsyyCameraApplyQueryBo bo) {
        List<ZsyyCameraApplyVo> list = iZsyyCameraApplyService.queryList(bo);
        ExcelUtil<ZsyyCameraApplyVo> util = new ExcelUtil<ZsyyCameraApplyVo>(ZsyyCameraApplyVo.class);
        return util.exportExcel(list, "摄像头开通");
    }

    /**
     * 获取摄像头开通详细信息
     */
    @ApiOperation("获取摄像头开通详细信息")
    @PreAuthorize("@ss.hasPermi('system:cameraApply:query')")
    @GetMapping("/{id}")
    public AjaxResult<ZsyyCameraApplyVo> getInfo(@NotNull(message = "主键不能为空")
                                                  @PathVariable("id") Long id) {
        return AjaxResult.success(iZsyyCameraApplyService.queryById(id));
    }

    /**
     * 新增摄像头开通
     */
    @ApiOperation("新增摄像头开通")
    @PreAuthorize("@ss.hasPermi('system:cameraApply:add')")
    @Log(title = "摄像头开通", businessType = BusinessType.INSERT)
    @RepeatSubmit
    @PostMapping()
    public AjaxResult<Void> add(@Validated @RequestBody ZsyyCameraApplyAddBo bo) {
        return toAjax(iZsyyCameraApplyService.insertByAddBo(bo) ? 1 : 0);
    }

    /**
     * 修改摄像头开通
     */
    @ApiOperation("修改摄像头开通")
    @PreAuthorize("@ss.hasPermi('system:cameraApply:edit')")
    @Log(title = "摄像头开通", businessType = BusinessType.UPDATE)
    @RepeatSubmit
    @PutMapping()
    public AjaxResult<Void> edit(@Validated @RequestBody ZsyyCameraApplyEditBo bo) {
        return toAjax(iZsyyCameraApplyService.updateByEditBo(bo) ? 1 : 0);
    }

    /**
     * 删除摄像头开通
     */
    @ApiOperation("删除摄像头开通")
    @PreAuthorize("@ss.hasPermi('system:cameraApply:remove')")
    @Log(title = "摄像头开通" , businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult<Void> remove(@NotEmpty(message = "主键不能为空")
                                       @PathVariable Long[] ids) {
        return toAjax(iZsyyCameraApplyService.deleteWithValidByIds(Arrays.asList(ids), true) ? 1 : 0);
    }
}
